package com.ecode.ecny.controller;

import com.ecode.ecny.dto.BaseReqDTO;
import com.ecode.ecny.dto.BaseRspDTO;
import com.ecode.ecny.dto.convert.ConvertInReqDTO;
import com.ecode.ecny.dto.convert.ConvertInRspDTO;
import com.ecode.ecny.dto.sign.SignReqDTO;
import com.ecode.ecny.dto.sign.SignRspDTO;
import com.ecode.ecny.flow.FlowExecutor;
import com.ecode.ecny.service.ConvertInService;
import com.ecode.ecny.service.sign.SignService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ConvertIn
 * @Author mjlft
 * @Date 2021/8/12 21:12
 * @Version 1.0
 * @Description 模拟兑回交易
 */

@RestController
@RequestMapping("/ecny")
public class TrxController {
    private Logger logger = LoggerFactory.getLogger(TrxController.class);

    @Autowired
    private FlowExecutor executor;

    @RequestMapping("/convert/in")
    public BaseRspDTO<ConvertInRspDTO> convertIn(@Validated @RequestBody BaseReqDTO<ConvertInReqDTO> convertInReqDTO){
        logger.info("请求参数-{}", convertInReqDTO);
        return executor.execute(ConvertInService.CONVERT_IN_FLOW, convertInReqDTO);
    }

    @RequestMapping("/sign/sign")
    public BaseRspDTO<SignRspDTO> sign(@Validated @RequestBody BaseReqDTO<SignReqDTO> reqDTO){
        logger.info("请求参数-{}", reqDTO);
        return executor.execute(SignService.SIGN_FLOW, reqDTO);
    }
}
